Skip to content

feat: 文件树拖拽到输入框生成 ContextMention(文件+目录)#171

Open
gy212 wants to merge 4 commits intoop7418:mainfrom
gy212:codex/filetree-dnd-contextmention
Open

feat: 文件树拖拽到输入框生成 ContextMention(文件+目录)#171
gy212 wants to merge 4 commits intoop7418:mainfrom
gy212:codex/filetree-dnd-contextmention

Conversation

@gy212
Copy link
Copy Markdown
Contributor

@gy212 gy212 commented Mar 5, 2026

变更说明

  • FileTree 文件/目录节点支持拖拽,写入自定义 MIME payload。
  • MessageInput 支持解析 FileTree 拖拽:
    • 拖文件:同时添加附件 + 文件 ContextMention chip。
    • 拖目录:添加目录 ContextMention chip。
  • 保留附件失败回退:无法读取文件时自动插入 @path
  • 发送前对 ContextMention 前缀去重,避免与输入中已有 @path 重复。
  • 发送按钮在仅有 ContextMention 时也可提交。

规格文档

  • 新增 docs/specs/product.md
  • 新增 docs/specs/architecture.md
  • 新增 docs/specs/tasks.md

测试与验证

pm run test 通过(85 passed, 0 failed)。

  • 浏览器自动化验证:拖拽文件会生成附件+文件 chip,拖拽目录会生成目录 chip,console 无报错。

额外修复

  • 修复 claude-session-parser 单测在 Windows 下的路径导入/家目录隔离问题:
    • 动态导入改为 pathToFileURL(...)。
    • 测试中补齐 HOME/USERPROFILE/HOMEDRIVE/HOMEPATH 隔离。

gy212 added 2 commits March 5, 2026 19:57
Implement file/folder drag payloads from FileTree and handle drops in MessageInput.

File drops now add both attachment and context mention chip; folder drops add directory chip.

Keep attachment failure fallback by inserting @path and dedupe mention prefixes on send.

Fix claude-session-parser unit tests on Windows by using file URL import and deterministic home env overrides.

Add spec-coding artifacts under docs/specs for this feature.
@gy212 gy212 force-pushed the codex/filetree-dnd-contextmention branch from 70622df to a73e5d5 Compare March 5, 2026 11:58
Copy link
Copy Markdown
Owner

@op7418 op7418 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #171 Review: 文件树拖拽到输入框生成 ContextMention

总体评价

功能方向合理,补齐了 FileTree → MessageInput 的拖拽链路。代码结构清晰,有完整的规范文档。但有几个需要关注的问题:

需要改进的地方

1. 规范文档不应随代码提交
docs/specs/ 下的 architecture.mdproduct.mdtasks.md 是开发过程的辅助文档,不应该合入主仓库。建议移除这些文件,或移至 docs/exec-plans/ 目录下(按项目约定)。

2. hasDragType 函数过度防御
src/components/chat/MessageInput.tsx 中的 hasDragType 函数对 dataTransfer.types 做了三种兼容检查(includescontainsArray.from)。现代浏览器中 DOMStringList 已经支持 includes,Electron 环境更不需要 contains 的 fallback。建议简化为直接用 Array.from(types).includes(type) 即可。

3. ContextMention chip 使用了固定 5 列网格

<div className="grid w-full grid-cols-5 gap-1.5 px-3 pt-2 pb-0 order-first">

当 mention 数量少于 5 个时会有大量空白,超过 5 个时也不会自动换行显示合适。建议改用 flex flex-wrap 布局。

4. 文件扩展名颜色映射可扩展性不足
getMentionColorClasses 中硬编码了 doc/xls/pdf/txt 等扩展名的颜色。建议至少补充常见代码文件扩展名(ts/js/py 等),或者简化为只区分 file/directory 两种颜色。

5. 缺少对 text/x-codepilot-path fallback MIME 的说明
定义了两个 MIME 类型 application/x-codepilot-pathtext/x-codepilot-path,但没有注释说明为什么需要 fallback。如果是为了某些浏览器兼容性,请补充注释。

6. useEffect 依赖数组中缺少 appendPathMention
拖拽相关的 useEffect 依赖了 addContextMention 但 drop handler 中通过 FileTreeAttachmentBridgeonAttachFailed 间接使用了 appendPathMention,如果 appendPathMention 引用变化可能导致闭包过期。

7. i18n 完整性
ContextMention 相关的用户可见文本(如拖拽提示)没有对应的 i18n key。虽然当前没有显式的拖拽提示文本,但 chip 的 tooltip 或 aria-label 应考虑国际化。

优点

  • 使用自定义 MIME 类型区分 FileTree 拖拽与外部拖拽,设计合理
  • 去重逻辑(发送前过滤已存在的 @path)考虑周全
  • FileTreeAttachmentBridgeonAttachFailed 回退机制完善
  • 测试文件的 pathToFileURL 修复是正确的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants